﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using UDS.Components;

namespace UDS.SubModule.UnitiveDocument.DocumentFlowPages
{
    /// <summary>
    /// ManageTache 的摘要说明。
    /// </summary>
    public partial class ManageTachePage : Page
    {
        protected override void OnInit(EventArgs e)
        {
            cmdNewTache.Click += cmdNewTache_Click;
            cmdDeleteTache.Click += cmdDeleteTache_Click;
            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Bangding();
                cmdDeleteTache.Attributes["OnClick"] = "javascript:return confirm('您确认要删除这些环节吗?');";
            }

            base.OnLoad(e);
        }

        private string GetSelectedItemID(string controlID)
        {
            string selectedID = "";
            //遍历DataGrid获得checked的ID
            foreach (DataGridItem item in dgTacheList.Items)
            {
                if (((CheckBox)item.FindControl(controlID)).Checked)
                {
                    selectedID += dgTacheList.DataKeys[item.ItemIndex] + ",";
                }
            }
            if (selectedID.Length > 0)
            {
                selectedID = selectedID.Substring(0, selectedID.Length - 1);
            }
            return selectedID;
        }

        public string TranslateRightToFinish(string tStr)
        {
            string str;
            if (tStr == "True")
            {
                str = "可以结束";
            }
            else
            {
                str = "不可结束";
            }

            return str;
        }

        public string TranslatePassNum(string tStr)
        {
            string str = "";
            if (tStr == "0")
            {
                str = "单人通过";
            }
            if (Int32.Parse(tStr) > 0)
            {
                str = tStr + "人会签";
            }
            if (Int32.Parse(tStr) < 0)
            {
                str = "全体通过";
            }

            return str;
        }

        public string TranslateFlowRule(string tStr)
        {
            switch (tStr)
            {
                case "0":
                    return "默认全体";
                case "1":
                    return "按部门";
                case "2":
                    return "按项目";
                default:
                    return "未知";
            }
        }

        private void cmdNewTache_Click(object sender, EventArgs e)
        {
            Server.Transfer("EditTache.aspx");
        }

        private void cmdDeleteTache_Click(object sender, EventArgs e)
        {
            string TacheID = GetSelectedItemID("cboTacheID");


            // TODO:
            // Finish the code below.
            //
            //df.DeleteTache(TacheID);
            //df = null;

            //Bangding();
        }

        #region 绑定DBGRID

        private void Bangding()
        {
            // TODO:
            // Finish the code below.
            //
            //DataTable dt;
            //df.GetTache(0,out dt);

            //dgTacheList.DataSource = dt.DefaultView;
            //dgTacheList.DataBind();

            //df =null;
        }

        #endregion

        #region 翻页事件

        public void DataGrid_PageChanged(object sender, DataGridPageChangedEventArgs e)
        {
            dgTacheList.CurrentPageIndex = e.NewPageIndex;
            Bangding();
        }

        #endregion
    }
}